<?php
$news = $this->items;
$dateFormat = \Managers\Utils::DATE_FORMAT;
if ($this->order) {
    $order = strcasecmp('asc', $this->order) == 0 ? 'desc' : 'asc';
} else {
    $order = 'asc';
}
?>
<div class="content-box">

    <div class="content-box-header">
        <h3>News</h3>
        <ul class="content-box-tabs">
            <li><a class="default-tab" href="#tab1">Table</a></li>
        </ul>
        <div class="clear"></div>
    </div>
    <div class="content-box-content">
        <div class="tab-content default-tab" id="tab1">
            <div class="row">
                <div class="span12">
                    <a class="btn" href="/admin/news/add">Add</a>
                    <table class="table table-striped">
                        <thead>
                        <tr>
                        <th style=" padding-top: 13px;vertical-align: top;">Сортировать по:

                                <?php
                                // обязательная форма для пост запроса
                                ?>
                                <form action="/admin/news" method="post">
                                    <input type="hidden" value="<?php echo $order ?>" name="order">
                                    <input type="hidden" value="id" name="column">
                                    <input type="submit" value="Id" class="btn"/>
                                </form>
                            </th>
                            <th>
                                <input type="button" class="btn" value="Title"/>
                            </th>
                            <th>
                                <form action="/admin/news" method="post">
                                    <input type="hidden" value="<?php echo $order ?>" name="order">
                                    <input type="hidden" value="date" name="column">
                                    <input type="submit" value="Date" class="btn"/>
                                </form>
                            </th>
                            <th>
                                <form action="/admin/news" method="post">
                                    <input type="hidden" value="<?php echo $order ?>" name="order">
                                    <input type="hidden" value="img" name="column">
                                    <input type="submit" value="Image" class="btn">
                                </form>
                            </th>
                            <th>
                                <input type="button" class="btn" value="Public">
                            </th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($news as $key => $article): ?>
                            <tr>

                                <td style="text-align: center"><?php echo $article['id'] ?></td>
                                <td><?php echo $article['title'] ?></td>
                                <td><?php echo  $article['date']->format($dateFormat) ?></td>
                                <td><input type="checkbox" disabled="disabled" <?php echo empty($article['img']) ? false: "checked" ?>></td>
                                <td>
                                    <input type="checkbox" disabled="disabled" <?php echo $article['public'] ? "checked" : false ?>>
                                </td>
                                <td>
                                    <a class="btn btn-success" href="/admin/news/edit/id/<?php echo $article['id'] ?>">Edit</a>
                                    <a class="btn btn-danger delete" href="/admin/news/delete/id/<?php echo $article['id'] ?>">Delete</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<?= $this->paginationControl($this->paginator, 'Sliding', 'paginator/digg.phtml') ?>